# Minimal makefile for Sphinx documentation

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS    ?=
SPHINXBUILD   ?= sphinx-build
SOURCEDIR     = source
BUILDDIR      = build

# 清理生成的API文档
clean-api:
	rm -rf $(SOURCEDIR)/D5Core
	rm -rf $(SOURCEDIR)/_autosummary
	rm -rf $(SOURCEDIR)/modules.rst

# 使用sphinx-apidoc生成API文档
.PHONY: apidoc
apidoc:
	python custom_apidoc.py

# 生成API文档并构建HTML
.PHONY: html
html: clean-api apidoc
	@$(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

# 帮助信息
.PHONY: help
help:
	@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

# 自动生成文档并实时预览
.PHONY: livehtml
livehtml: clean-api apidoc
	sphinx-autobuild "$(SOURCEDIR)" "$(BUILDDIR)/html" $(SPHINXOPTS) $(O)

.PHONY: Makefile
%: Makefile
	@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
